#ifndef __BITEXT_HH__
#define __BITEXT_HH__

#include <fstream>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#include "Tokenizer.hh"
#include "Vocabulary.hh"

/**
 * Defines a (source, target) sentence pair as found in the training
 * data.
 */
class Bitext;
class SentencePair{
  friend class Bitext;
  friend class Model;

public:
  void print(Bitext &, ostream &);
  void print_aachen(Bitext &, int, double, ostream &);
  
  bool is_labeled_training_example();
  bool is_labeled_testing_example();

  int n;
  set<pair<int, int> > alignment;

  string source;
  Tokenizer source_tokenizer;
  vector<int> source_ids;
  int J;

  string target;
  Tokenizer target_tokenizer;
  vector<int> target_ids;
  int I;

private:
  set<pair<int, int> > alignment_labeling;
  bool labeled;
  bool for_train;
};

/**
 * Defines a corpus of SentencePairs.
 */
class Model;
class Bitext{
public:
  /**
   * Indicate where the corpus is on disk.
   */
  Bitext(string);
  /**
   * Get the next sentence pair. Returns false if no further sentence
   * pairs.
   */
  bool next(SentencePair &);
  /**
   * Rewind to the beginning of the corpus.
   */
  void rewind();
  /**
   * Verbosely inspect the given golden alignments with respect to the
   * model. Give an interation number for helpful output.
   */
  void inspect(Model *, string, string, string, int);
  /**
   * Returns the same of the source file.
   */
  string get_filename();

  Vocabulary source_vocabulary;
  Vocabulary target_vocabulary;

private:
  string filename;
  int read_so_far;
  ifstream ifs;
};

#endif
